cd ${work}5_reg_analysis

local ylist		"log_vrd_exp_exsmall log_quantity log_price"
local felist	`" "IDY FPD FPY" "'
local wlist		`" "" "'

use temp\regsample_ipdt, clear

gen x1_ols	= treated_2
gen x2_ols 	= treated_2_pdy
gen x1_iv	= treated_2
gen x2_iv	= treated_2_pdy
gen z1		= tdcinitiative_2
gen z2		= tdcinitiative_2_pdy

lab var x1_ols	"Support"
lab var x2_ols	"Spillover"
lab var x1_iv	"Support"
lab var x2_iv	"Spillover"

eststo clear
local mtitles
local n=1
foreach y of local ylist {
local nfe=1	
foreach fe of local felist {
	
	local w : word `nfe' of `wlist'
	
	eststo est1: reghdfe `y' x1_ols x2_ols `w', a(`fe') vce(cl F) nosamp
		
	eststo est2: ivreghdfe `y' ( x1_iv x2_iv = z1 z2 ) `w', a(`fe') cl(F)
	local N = e(N)
	local F = e(widstat)
	
	eststo stacked_`n' : appendmodels est1 est2
	eststo drop est*
	qui estadd scalar N `N'
	qui estadd scalar F `F'
	qui estadd local FE `fe'
	if "`w'"!=""	qui estadd local SC "Yes"
	if "`w'"==""	qui estadd local SC "No"
	local mtitles `mtitles' "`:var lab `y''"
		
	local ++n
	local ++nfe
	
}	
}
	
esttab using output\table_a10.tex , replace booktabs se label ///
	title("Spill-overs Across Firms Within Treated Destination Markets") star(* 0.1 ** 0.05 *** 0.01) mtitles(`mtitles') keep(x?_*) ///
	stats(N F FE SC , labels("Observations" "IV F-stat" "Fixed Effects" "Size Control") fmt(%10.0fc %10.0fc "" "")) ///
	refcat(x1_ols "OLS" x1_iv "2SLS", nolabel)